//
// Created by pzw on 24-3-21.
//

#include "RangeFunc.h"

template<template<typename, typename ...> class Cont, typename Tp>
int RangeFunc::range_func_forEach(Cont<Tp> &vs, std::function<void(Tp &)> function) {
    std::cout << "range_func_forEach: vs = {" << std::endl;
    for (auto it = std::begin(vs); it != std::end(vs); ++it) {
        std::cout << *it << ", ";
        function((*it));
    }
    std::cout << "}" << std::endl;
    return 0;
}

template<class Cont, typename Tp>
int RangeFunc::range_func_forEach2(Cont &vs, std::function<void(Tp &)> function) {
    std::cout << "range_func_forEach2: vs = {" << std::endl;
    for (auto it = std::begin(vs); it != std::end(vs); ++it) {
        std::cout << *it << ", ";
        function((*it));
    }
    std::cout << "}" << std::endl;
    return 0;
}

int RangeFunc_main() {
    using namespace std;

    vector<int> v{1, 2, 3, 4, 5};
    const function<void(int &)> &func = [](int &e) -> void {
        cout << "RangeFunc_main: range_func_forEach e=" << e << endl;
    };
    RangeFunc::range_func_forEach(v, func);

    int a[]{5, 4, 3, 2, 1};
    const function<void(int &)> &func2 = [](int &e) -> void {
        cout << "RangeFunc_main: range_func_forEach2 e=" << e << endl;
    };
    RangeFunc::range_func_forEach2(a, func2);
    return 0;
}
